<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
</head>

<body>
  <script>
    //求最大值函数
    function getMax(x, y) {
      return x > y ? x : y
    }
    let m = getMax(1, 2)
    console.log(m)

    //求数组的最大最小值，并返回
    function getArrValue(arr = []) {
      let max = arr[0]
      let min = arr[0]
      for (let i = 1; i < arr.length; i++) {
        if (max < arr[i]) {
          max = arr[i]
        }
      }
      for (let i = 1; i < arr.length; i++) {
        if (min > arr[i]) {
          min = arr[i]
        }
      }
      return [max, min]
    }
    let newArr = getArrValue([2, 56, 7, 4, 19, 43, 10])
    console.log(newArr);
    console.log(`数组的最大值为:${newArr[0]}`)
    console.log(`数组的最小值为:${newArr[1]}`)

  </script>
</body>

</html>